﻿@{
    QResult DataFromController = (QResult)Model;

    Pager pager = DataFromController.Pager;

    string previousPageLink = DataFromController.CurrentUrl + "/" + (DataFromController.PageNumber - 1).ToString();
    string nextPageLink = DataFromController.CurrentUrl + "/" + (DataFromController.PageNumber + 1).ToString();


    int startingRunningPageNumber = pager.CurrentPageIndex - 5;

    if (startingRunningPageNumber < 1)
    {
        startingRunningPageNumber = startingRunningPageNumber = 1;
    }

    int endingRunningPageNumber = startingRunningPageNumber + 8;


    if (endingRunningPageNumber > pager.LastPageIndex - 1)
    {
        endingRunningPageNumber = pager.LastPageIndex;
    }

    string color = "#f44";
}
@if (pager.IsEmpty == false)
{
    <div class="pagination pagination-centered pagination-large" style="clear: both;">
        <ul style="background-color:#fff;">
            @if (pager.CurrentPageIndex > 1)
            {
                <li><a style="color:@color" href="@previousPageLink"><b>&larr; Previous</b></a>
                </li>
               
            }
            else
            {
                <li class="disabled"><a>&larr; Previous</a> </li>
                
            }
            @if (pager.IsFirstSegment == false && startingRunningPageNumber > 1)
            {
                <li><a href="@DataFromController.CurrentUrl">1</a> </li>
                if (startingRunningPageNumber > 2)
                {
                <li class="disabled bgscr"><a>...</a> </li>
                }
            }
            
            

@*@for (int i = pager.CurrentPageIndex-5; i < pager.NextPageIndex + 10 && i < pager.LastPageIndex; i++)*@
          
               
                    @for (int i = startingRunningPageNumber; i <= endingRunningPageNumber; i++)
                    {

                        if (pager.CurrentPageIndex == i)
                        {
                        <li class="active bgscr"><a>@i</a> </li>
                        }
                        else
                        {
                        <li class="bgscr"><a href="@DataFromController.CurrentUrl/@i">@i</a> </li>
                        }

                    }
               
           
            @if (pager.IsLastSegment == false || endingRunningPageNumber < pager.LastPageIndex)
            {
                <li class="disabled bgscr"><a>...</a> </li>
                <li class="bgscr"><a href="@DataFromController.CurrentUrl/@(pager.LastPageIndex)">
                    @(pager.LastPageIndex)</a> </li>
            }
            @if (pager.CurrentPageIndex >= pager.LastPageIndex)
            {
                <li class="disabled"><a>Next &rarr;</a> </li>
            }
            else
            {
                <li><a style="color:@color"  href="@nextPageLink"><b>Next &rarr;</b></a> </li>
            }
        </ul>
    </div>
}
